package org.geeks.service.impl;

import java.util.List;

import org.geeks.domain.User;
import org.geeks.repository.UserRepository;
import org.geeks.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class UserServiceImpl implements UserService {

	@Autowired
	private UserRepository userRepository;

	@Override
	public List<User> findAll() {
		return (List<User>) userRepository.findAll();
	}

	@Override
	public Page<User> findByPage(Integer page, Integer size) {
		return null;
	}

	@Override
	public User insertUser(User user) {
		return userRepository.save(user);
	}

	@Transactional
	@Override
	public Boolean insertUserBatch(List<User> users) {
		try {
			users.forEach((user) -> {
				userRepository.save(user);
			});
			Integer.parseInt("string");
		} catch (Exception e) {
			log.error("批量插入用户异常", e);
			throw e;
		}
		return true;
	}

	@Override
	public Boolean insertUserBatchX(List<User> users) {
		return true;
	}

	@Override
	public User updateUser(User user) {
		return userRepository.save(user);
	}
}
